package pers.archives.loginToken.authentication;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.stereotype.Component;
import pers.archives.common.constant.ResponseConstant;
import pers.archives.common.ov.common.CommonResponse;
import pers.archives.common.ov.common.ResponseCode;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 *@program:archives-parent
 *@author: 赵浩浩
 *@Time: 2020/9/12  12:49
 */
@Slf4j
@Component
public class ArchivesAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        CommonResponse<String> commonResponse = new CommonResponse(
                ResponseCode.USER_LOGIN_ERROR, null
        );
        response.setContentType(ResponseConstant.RESPONSE_CONTENT);
        response.getWriter().write(commonResponse.toString());
    }
}
